//获取请求参数, 并返回JSON数据

let http = require('http');

http.createServer(function (request, response) {

  let urlStr = request.url;//获取请求额URL
  if (urlStr !== "/favicon.ico") {

    let url = new URL(urlStr, "http://localhost:8080/")// 拼接为完整的URL

    let objUser = {}
    for (let [k, v] of url.searchParams) {// 结构
      objUser[k] = v;//将数据放入对象中
    }
    console.log(objUser);

    response.writeHead(200, {
      "Content-Type": "application/json; charset=utf-8"//设置响应内容为JSON
    })
    response.write(JSON.stringify(objUser));// 将JS对象转为JSON字符串
    response.end()
  }

}).listen(8080, function () {
  console.log("服务器已经启动,监听端口号为8080");
});